from sqlalchemy import Column, Integer, String, Text, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
import uuid

from db.base import Base

class Attachment(Base):
    """附件模型"""
    __tablename__ = "attachment"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    compliance_item_id = Column(UUID(as_uuid=True), ForeignKey("compliance_item.id", ondelete="CASCADE"))
    name = Column(String(255), nullable=False)
    path = Column(Text, nullable=False)
    type = Column(String(50), nullable=False)
    size = Column(Integer, nullable=False)

    # 关系
    compliance_item = relationship("ComplianceItem", back_populates="attachments") 